package jp.co.brilliantservice.hacks.useVideoView;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.widget.VideoView;

public class UseVideoViewActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
		public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		VideoView vv = (VideoView) findViewById(R.id.video);
		
		
		String dst = "http://59.64.176.73:8000/video/iVideo_20121102153514.mp4"; 
		vv.setVideoPath(dst);
		vv.start();
		
		// メディア再生完了
		vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
			public void onCompletion(MediaPlayer mp) {
				Log.v("useVideoView", "onCompletion");
			}
		});

		
		vv.setOnErrorListener(new MediaPlayer.OnErrorListener() {
			public boolean onError(MediaPlayer mp, int what, int extra) {
				switch(what) {
				
				case MediaPlayer.MEDIA_ERROR_UNKNOWN:
					Log.v("useVideoView", "MEDIA_ERROR_UNKNOWN");
					return true;
				
				case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
					Log.v("useVideoView", "MEDIA_ERROR_SERVER_DIED");
					return true;
				
				case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
					Log.v("useVideoView", 
						  "MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK");
					return true;
				}
				return false;
			}
		});
	}
}